<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="content">
        <h2>返回首页</h2>
        <div class="goTop">返回</div>
    </div>
</body>


<script>
    let goTop = document.getElementsByClassName("goTop")[0];
    window.onscroll = function(){
        let res = document.body.scrollTop || document.documentElement.scrollTop;
        if(res>=400){
            goTop.style.display="block";
        } else{
            goTop.style.display="none";
        }
    }
    goTop.onclick = function(){
        document.body.scrollTop = 0;
        document.documentElement.scrollTop = 0;
    }
</script>


<style>
    body {
        height: 9999px;
    }


    .goTop{
        width: 100px;
        height: 100px;
        background-color: #bbb;
        text-align: center;
        line-height: 100px;
        position: fixed;
        bottom: 100px;
        right: 20px;
        display: none;
    }
</style>

</html>